import { createContext, Dispatch, ReactNode, SetStateAction, useState } from "react";

export type SetWebsiteType = {
    title: ReactNode;
};
export type WebsiteContextType = SetWebsiteType & {
    setWebsite: Dispatch<SetStateAction<SetWebsiteType>>;
};

export const WebsiteContext = createContext<WebsiteContextType>({
    title: '',
    setWebsite: () => null,
});
function WebsiteProvider({children}: {
    children: React.ReactNode,
}) {
    const [website, setWebsite] = useState<SetWebsiteType>(() => ({
        title: ''
    }));

    return <WebsiteContext.Provider value={{
        ...website,
        setWebsite: (reWebsite) => setWebsite({...website, ...reWebsite})
    }}>
        {children}
    </WebsiteContext.Provider>;
}

export default WebsiteProvider;